<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
   xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:p="http://primefaces.org/ui"
   xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
   template="/WEB-INF/templates/default.xhtml">
   
   	<f:metadata>
	   	<f:viewParam name="violationRecordId" value="#{violationRecordHome.id}"></f:viewParam>
	   	<f:event listener="#{violationRecordHome.initConversation()}" type="preRenderView"></f:event>
	   		   	
	   	<f:viewParam name="moduleName" value="违规处罚管理"></f:viewParam>
	   	<f:viewParam name="approvedType" value="#{approvedClassList.approvedType}"></f:viewParam>
   	</f:metadata>
   
   	<ui:define name="content">
   
		<h:form id="editForm">         
			<p:panel id="panel" header="#{violationRecordHome.managed ? '修改' : '新增'}违规处罚记录" style="margin-bottom:10px;">
		        <p:messages id="messages" closable="true"><p:autoUpdate/></p:messages>
		        
		        <h:panelGrid columns="2" cellpadding="5">
					<p:outputLabel for="serviceSupplier" value="中介机构" />
					<p:outputPanel>									
						<p:inputText id="serviceSupplier" 
							  	  value="#{violationRecordHome.instance.serviceSupplier.cnname}"						  	   
						   	   required="true"						   	   
						   	   	   size="50"
						   	 readonly="#{facesContext.currentPhaseId.ordinal eq 6}" />
						<p:commandButton value="选择" oncomplete="PF('chooseSupplierDialog').show();" immediate="true"></p:commandButton>
					</p:outputPanel>
						   
				    <p:outputLabel for="approvedClass" value="考核类别" />				
					<p:selectOneMenu id="approvedClass" 
							  value="#{approvedClassHome.instance}"
						   required="true">
						<f:selectItem itemLabel="请选择" itemValue="#{null}" />
						<f:selectItems value="#{approvedClassList.resultList}" var="_class" itemLabel="#{_class.name}" itemValue="#{_class}"></f:selectItems>
						<f:converter converterId="entityConverter"></f:converter>
						<p:ajax update="@form:approvedMatter"></p:ajax>
					</p:selectOneMenu>
					
					<p:outputLabel for="approvedMatter" value="考核事项" />
					<p:selectOneMenu id="approvedMatter" 
							  value="#{violationRecordHome.instance.approvedMatter}"
						   required="true">
						<f:selectItem itemLabel="请选择" itemValue="#{null}"/>
						<f:selectItems value="#{approvedMatterList.resultList}" var="_matter" itemLabel="#{_matter.matterName}" itemValue="#{_matter}"></f:selectItems>
						<f:converter converterId="entityConverter"></f:converter>
						<p:ajax event="change" update="@form:evidencesPanel" />
					</p:selectOneMenu>	
					
					<p:outputLabel for="occurrenceTime" value="违规时间"></p:outputLabel>
					<p:calendar id="occurrenceTime"						
						value="#{violationRecordHome.instance.occurrenceTime}" 
						required="true"
						pattern="yyyy-MM-dd" locale="zh_CN" 
						showOn="button"
						readonlyInput="true" />
					
					<p:outputLabel for="desc">违规事实描述</p:outputLabel>
					<p:inputTextarea id="desc"
									value="#{violationRecordHome.instance.desc}"
									required="true"
									cols="80"
									rows="5">					
					</p:inputTextarea>
				</h:panelGrid>
			</p:panel>
			
			<p:panel id="evidencesPanel" header="证据材料">
				<p:panelGrid>
					
					<p:repeat var="_def" value="#{violationRecordHome.instance.approvedMatter.evidenceDefinations}">
						<p:row>
							<p:column>
								<div style="width: 100px; margin: 0;">
									<p:outputLabel for="evidenceAttachment" value="#{_def.name}"></p:outputLabel>
								</div>								
							</p:column>
							<p:column>
								<p:fileUpload 
									id="evidenceAttachment"
									required="#{_def.required}"
									invalidSizeMessage="附件大小不能超过3M!"
									sizeLimit="#{1024 * 1024 * 3}"
									uploadLabel="上传"
									cancelLabel="取消"
									fileUploadListener="#{violationRecordController.uploadEvidence}"></p:fileUpload>
							</p:column>
						</p:row>
					</p:repeat>	
					
				</p:panelGrid>				
			</p:panel>
			
			<p:commandButton action="#{violationRecordController.save()}" value="保存" ajax="false" />
			<p:commandButton value="删除" action="#{violationRecordHome.delete()}">
				<p:confirm header="请确认" message="您确认删除记录吗?" icon="ui-icon-alert" />
			</p:commandButton>
			<p:commandButton action="#{violationRecordHome.cancel()}" value="取消" immediate="true"></p:commandButton>	
						
			<p:confirmDialog id="confirmDialog" global="true" showEffect="fade" hideEffect="explode" widgetVar="confirmDialog">
			    <p:commandButton value="确认" styleClass="ui-confirmdialog-yes"></p:commandButton>
			    <p:commandButton value="取消" immediate="true" styleClass="ui-confirmdialog-no" />
			</p:confirmDialog>
		</h:form>
		
		<p:dialog id="chooseSupplierDialog" 
		   widgetVar="chooseSupplierDialog"
		   	   width="640"
		   	  height="580"
		   	   modal="true">
		   	   
		   <h:form>
		   				
					
					<p:outputLabel for="cnname" value="中介机构名称"></p:outputLabel>
					<p:inputText id="cnname" value="#{serviceSupplierList.cnname}" immediate="true"></p:inputText>
					<p:commandButton value="查询" action="#{serviceSupplierList.refresh()}" update=":chooseSupplierForm:dialogData">
					</p:commandButton>
		   </h:form>
		   	   
		   <h:form id="chooseSupplierForm">
				<p:panel>
					<f:facet name="header">选择中介机构</f:facet>
					
					<p:outputPanel id="dialogData">
						<p:selectOneRadio id="supplierRadio" value="#{violationRecordHome.instance.serviceSupplier}" layout="custom">
							<f:selectItems value="#{serviceSupplierList.resultList}" var="_supplier" itemLabel="#{_supplier.cnname}" itemValue="#{_supplier}"></f:selectItems>
							<f:converter converterId="entityConverter"></f:converter>
						</p:selectOneRadio>			
						
						<p:dataTable var="_supplier" rowIndexVar="_status" value="#{serviceSupplierList.resultList}">
							<p:column style="width: 20px;">
								<p:radioButton for=":chooseSupplierForm:supplierRadio" itemIndex="#{_status}" >
								</p:radioButton>
							</p:column>
							<p:column headerText="中介机构名称">
								<h:outputText value="#{_supplier.cnname}" />
							</p:column>
							<p:column headerText="地址">
								<h:outputText value="#{_supplier.address}" />
							</p:column>
						</p:dataTable>
					</p:outputPanel>
			
					<p:commandButton value="前页" action="#{serviceSupplierList.refresh()}" update=":chooseSupplierForm:dialogData" immediate="true">
						<f:setPropertyActionListener value="#{serviceSupplierList.firstResult - 10 &lt; 0 ? 0 : serviceSupplierList.firstResult - 10}" target="#{serviceSupplierList.firstResult}"></f:setPropertyActionListener>
					</p:commandButton>
					<p:commandButton value="下页" action="#{serviceSupplierList.refresh()}" update=":chooseSupplierForm:dialogData" immediate="true">
						<f:setPropertyActionListener value="#{serviceSupplierList.firstResult + 10 &gt; serviceSupplierList.resultCount ? serviceSupplierList.resultCount : serviceSupplierList.firstResult + 10}" target="#{serviceSupplierList.firstResult}"></f:setPropertyActionListener>
					</p:commandButton>
					
					<f:facet name="footer">
						<p:commandButton value="保存" oncomplete="PF('chooseSupplierDialog').hide();" update=":editForm:serviceSupplier" />
						<p:commandButton value="取消" onclick="PF('chooseSupplierDialog').hide();" immediate="true"/>
					</f:facet>
				</p:panel>
			</h:form>			
		</p:dialog>
        
   	</ui:define>
</ui:composition>
